
<template>
    <el-form 
    
    ref="form" 
   
    :model="form" 
    
    label-width="80px" 
    enctype="multipart/form-data" >
        
        <el-form-item 
        label="分类名"
       
         >
            <el-input  v-model="form.typename" ></el-input>
            
        </el-form-item>
        <el-form-item 
        label="分类描述"
       
         >
            <el-input  v-model="form.description" ></el-input>
            
        </el-form-item>
        
   
        <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button>取消</el-button>
        </el-form-item>
    </el-form>
</template>


<script>
import axios from 'axios'
import { mapState } from 'vuex'
import Editor from 'index/components/Editor'


export default {
    name:'TypeForm', 
    inject:['reload'], 
    components:{
        Editor 
    },
    data() {
        return {
           
            form: {
                typename: '',
                description:''
                
            },
            formData: new FormData(),
           
        }
    },
    mounted() {
        
    },
    computed:{
        ...mapState(['baseUrl'])
    },
    methods: {
        onSubmit() {
             let that = this
            var typename = this.form.typename;
            var description = this.form.description;
            if(typename==''){
                const h = this.$createElement;

                this.$notify({
                title: '警告',
                type: 'warning',
                offset: 100,
                message: h('i', { style: 'color: teal'}, '种类名所有信息必须填写')
                });
                return false;
            }
            //下面append的东西就会到form表单数据的fields中；
            that.formData.append('name', typename);
            that.formData.append('description',description);
            
             
            
            // console.log(that.formData)
            let config = {
                headers: {
                    'Content-Type': 'multipart/form-data'
                    
                },
                
                
            }
            that.$refs.upload.submit();
            axios.post(this.baseUrl+"product/addType", this.formData, config).then(function(result) {
                            console.log(result);
                            // alert(result.data);

                           

                            if(result.data===true){
                                that.$alert('新增成功', '特别提示', {
                                confirmButtonText: '确定',
                                closeOnClickModal:true,
                                center:true,
                                callback: action => {
                                    that.reload();
                                    that.$message({
                                    message: '恭喜你，这是一条成功消息',
                                    type: 'success',
                                    duration:'3000',
                                    showClose:true,
                                    });
                                }
                            });
                                
                            }

                            
            })
            

        }
       
    }
}
</script>
<style lang="stylus">
.el-message-box__wrapper
    z-index 20003!important
</style>
